/**
 * Created by 陈豆豆 2019-06-24
 */
window.onload = function (ev) {
    topbar.hide();
};
var myDate = new Date();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
if (month < 10) {
    month = "0" + month;
}
if (day < 10) {
    day = "0" + day;
}
var _start = myDate.getFullYear() + '-' + month + '-' + day + " 00:00:00";
var _end = myDate.getFullYear() + '-' + month + '-' + day + " 23:59:59";
$("#startTime").val(_start);
$("#endTime").val(_end);
laydate.render({
    elem: '#startTime',
    type: 'datetime',

});
laydate.render({
    elem: '#endTime' //指定元素
    , type: 'datetime',
});
$('#dataTable').bootstrapTable({
    url: '/aliProgramReport/queryAliProgramStatistics',
    height: $(window).height() - 200,
    pageSize: 30,
    pagination: true,
    pageList: [30, 50, 100],
    clickToSelect: true,
    queryParams: queryParams,
    uniqueId: 'id',
    queryParamsType: '',
    sidePagination: 'server',
    showFooter: true,
    responseHandler: function (res) {
        return {
            "total": res.total,
            "rows": res.resultList
        };
    },
    columns: [[
        {
            width: '3px',
            align: 'center',
            formatter: function (v, row, index) {
                return index + 1
            }
        },
        {
            field: 'operatorName', title: '运营商', width: 90, align: 'center'
        },
        {
            field: 'face', title: '面值', width: 90, align: 'center', sortable: true

        }, {
            field: 'totalNum', title: '收卡笔数', width: 90, align: 'center',
            footerFormatter: function (value) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].totalNum);
                }
                return count + "";
            }
        }, {
            field: 'successNum', title: '实销笔数', width: 90, align: 'center',
            footerFormatter: function (value) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].successNum);
                }
                return count + "";
            }
        }, {
            field: 'settlePrice', title: '实销金额', width: 90, align: 'center',
            footerFormatter: function (value) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].settlePrice);
                }
                return count.toFixed(4) + "";
            }
        },
        {
            field: 'failNum', title: '失败笔数', width: 90, align: 'center',
            footerFormatter: function (value) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].failNum);
                }
                return count + "";
            }
        },
        {
            field: 'saleableNum', title: '在售笔数', width: 90, align: 'center',
            footerFormatter: function (value) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].saleableNum);
                }
                return count + "";
            }
        },
        {
            field: 'processingNum', title: '处理中笔数', width: 90, align: 'center',
            footerFormatter: function (value) {
                var count = 0;
                for (var i in value) {
                    count = parseFloat(count) + parseFloat(value[i].processingNum);
                }
                return count + "";
            }
        }
    ]]
})
;
$("#search").click(function () {
    var timeAdd = new Date($("#startTime").val());
    var timeEnd = new Date($("#endTime").val());
    if (timeAdd > timeEnd) {
        layer.msg("开始时间不能大于结束时间");
        return false;
    }
    var require = (timeEnd - timeAdd) / (1 * 24 * 60 * 60 * 1000);
    if (require > 7) {
        layer.msg("时间间隔不能超过7天");
        return;
    }
    $("#dataTable").bootstrapTable("refresh");
});

function queryParams(params) {
    return {
        size: params.pageSize,
        page: params.pageNumber,
        startTime: $("#startTime").val(),
        endTime: $("#endTime").val(),
        timeType: $("#timeType").val()
    };
}